#ifndef _HTTP_H
#define _HTTP_H

#include <netinet/in.h>
#include "buffer.h"

extern const char *M_GET;
extern const char *M_POST;

extern const char *CONN_TYPE_CLOSE;

/**
 * GET / HTTP/1.1\r\n
 * Accept: %s\r\n       accept_type
 * Host: %s:%d\r\n      ip:port
 * Connection: %s\r\n   connection_type
 * Content-Type: application/x-www-form-urlencoded\r\n
 * Content-Length: %d\r\n  strlen(body)
 * \r\n
 * %s                      body
 * if programer use GET method,body should be NULL 
**/

struct robot_context{
	struct bufferFactory *factory;
};

extern struct robot_context* http_robot_context_build();
extern int http_robot_context_release(struct robot_context *context);

extern int http_request_head(struct robot_context *context,struct buffer **request,const char *method,char *url,char *accept_type,char *ip, int port,const char *conn_life, char *body);
extern int http_addr_reset(struct sockaddr_in *addr,char *host,int port);
extern int http_fetch(struct robot_context *context,struct buffer *request,struct sockaddr_in *addr,struct buffer **response);

#endif